/**
 * @description  : 数据表初始化
 * @descriptionDetail : 数据表初始化
 * @copyright    : 浙江烟草
 * @author       : mc
 * @create       : 2022-12-03 13:55:29
 */
import {
  goods,
} from './case/sql.js';
import {keySearchInfo,} from './keySearch/sql.js';

// 初始化 判断是否创建表
const initDb = function(webDb) {
  let sqls = new Array();

  return new Promise(function(resolve, reject) {
    // #ifdef H5
    // indexdb store语句必须初始化执行
    sqls.push(
      goods.createSQL_H5,
      keySearchInfo.createSQL_H5,
    );
    // #endif
    // #ifdef APP-PLUS
    let isInitDb = uni.getStorageSync('INIT_DB');
    if (isInitDb == '1') { // 标记表示已经创建过了
      resolve();
      return;
    }
    sqls.push(
      goods.createSQL,
      keySearchInfo.createSQL,
    );
    // #endif
    webDb.createTableBath(sqls, () => {
      uni.setStorageSync('INIT_DB', '1');
      resolve();
    }, () => {
      reject()
    });
  });
}

export default {
  initDb,
}
